package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.DishDto;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("SELECT COUNT(*) FROM dish WHERE category_id=#{categoryId}")
    Long findDishByCategory(Long id);

    @Insert("INSERT INTO dish VALUES (null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0);")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void save(DishDto dishDto);

    List<Dish> findByName(String name);

    @Select("SELECT * FROM dish WHERE id =#{id}")
    Dish findById(Long id);

    void updateById(DishDto dishDto);


    List<Dish> findByCategoryId(@Param("categoryId") Long categoryId, @Param("status") Integer status);

    void deleteByIds(@Param("ids") List<Long> ids);

    void setStatus(@Param("status") Integer status, @Param("ids") List<Long> ids);
}
